package flc.ast.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import flc.ast.bean.MyDebugBean;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void saveTcpServerList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_tcp_server_list, json);
    }

    public static List<MyDebugBean> getTcpServerList() {
        String json = sSpUtils.getString(Key.key_tcp_server_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveTcpClientList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_tcp_client_list, json);
    }

    public static List<MyDebugBean> getTcpClientList() {
        String json = sSpUtils.getString(Key.key_tcp_client_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveUdpServerList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_udp_server_list, json);
    }

    public static List<MyDebugBean> getUdpServerList() {
        String json = sSpUtils.getString(Key.key_udp_server_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveUdpClientList(List<MyDebugBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_udp_client_list, json);
    }

    public static List<MyDebugBean> getUdpClientList() {
        String json = sSpUtils.getString(Key.key_udp_client_list);
        return GsonUtils.fromJson(json, new TypeToken<List<MyDebugBean>>() {
        }.getType());
    }

    public static void saveTraceRecordList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_trace_record_list, json);
    }

    public static List<String> getTraceRecordList() {
        String json = sSpUtils.getString(Key.key_trace_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    public static void saveTcpRecordList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_tcping_record_list, json);
    }

    public static List<String> getTcpRecordList() {
        String json = sSpUtils.getString(Key.key_tcping_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    public static void saveMtrRecordList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_mtr_record_list, json);
    }

    public static List<String> getMtrRecordList() {
        String json = sSpUtils.getString(Key.key_mtr_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    public static void saveExploreRecordList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_explore_record_list, json);
    }

    public static List<String> getExploreRecordList() {
        String json = sSpUtils.getString(Key.key_explore_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    public static void saveDnsRecordList(List<String> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_dns_record_list, json);
    }

    public static List<String> getDnsRecordList() {
        String json = sSpUtils.getString(Key.key_dns_record_list);
        return GsonUtils.fromJson(json, new TypeToken<List<String>>() {
        }.getType());
    }

    interface Key {
        String key_tcp_server_list = "key_tcp_server_list";
        String key_tcp_client_list = "key_tcp_client_list";
        String key_udp_server_list = "key_udp_server_list";
        String key_udp_client_list = "key_udp_client_list";
        String key_trace_record_list = "key_trace_record_list";
        String key_tcping_record_list = "key_tcping_record_list";
        String key_mtr_record_list = "key_mtr_record_list";
        String key_explore_record_list = "key_explore_record_list";
        String key_dns_record_list = "key_dns_record_list";


    }
}